/************************************************************************/
// Copyright (C) 2016, han_gangbiao. All rights reserved.
// Use of this source code is governed by a GPL-v2 license that can be found in the License file.
// 
// [Time]:      2016-1-4 21:53:17
// [Author]:    han_gangbiao [http://my.oschina.net/jackhen]
// [Info]:      
/************************************************************************/

#include "xatomic.h"
BEG_NS_SMART

long atomic_t::get() const
{
    return __sync_val_compare_and_swap(const_cast<volatile long*>(&m_value), 0, 0);
}

long atomic_t::set(long v)
{
    return __sync_lock_test_and_set(&m_value, v);
}

long atomic_t::inc()
{
    return __sync_add_and_fetch(&m_value, 1);
}

long atomic_t::dec()
{
    return __sync_add_and_fetch(&m_value, -1);
}

bool atomic_t::cas(long cmp, long newvalue)
{
     return __sync_bool_compare_and_swap(const_cast<volatile long*>(&m_value), cmp, newvalue);
}


END_NS_SMART
